package com.example.mvc.controller;

import com.example.mvc.bean.Book;
import com.example.mvc.bean.User;
import com.example.mvc.service.BookService;
import com.example.mvc.service.UserService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/updateReadUserServlet")
public class UpdateReadUserServlet extends HttpServlet {
 UserService userService = new UserService();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String name = request.getParameter("name");
        String email = request.getParameter("email");
        String phone = request.getParameter("phone");
        //Integer 类：parseInt() 方法用于将字符串参数作为有符号的十进制整数进行解析
        //借阅最大天数
        int max_num = Integer.parseInt(request.getParameter("max_num"));
        //最大可借数
        int lend_num = Integer.parseInt(request.getParameter("lend_num"));
        //用户id
        int aid = Integer.parseInt(request.getParameter("aid"));

        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setName(name);
        user.setEmail(email);
        user.setPhone(phone);
        user.setMax_num(max_num);
        user.setLend_num(lend_num);
        user.setAid(aid);
        int cunt = userService.updateReadUser(user);
        String contextPath = request.getContextPath();
        resp.sendRedirect(contextPath+"/getUserList");

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
